#include "thread.h"

namespace reldt {

void *Thread::entry(void *arg)
{
    Thread *task = (Thread *)arg;
    task->func(task->arg);
	pthread_exit(NULL);
	return NULL;
}

void Thread::start(Func f, void *a)
{
	pthread_attr_t attr;
    func = f;
    arg = a;

	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
	pthread_create(&tid, &attr, entry, this);
	pthread_attr_destroy(&attr);
}

void Thread::join()
{
	void *ret;
	pthread_join(tid, &ret);
}

}
